<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑任务</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <form class="layui-form layuimini-form" action="" lay-filter="edit">
            <div class="layui-form-item">
                <label class="layui-form-label required">任务名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" lay-reqtext="任务名是必填项"
                           placeholder="请输入任务名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">表达式</label>
                <div class="layui-input-block">
                    <input type="text" name="pattern" lay-verify="required" lay-reqtext="表达式是必填项"
                           placeholder="请输入表达式" autocomplete="off" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">参考地址:<a href="https://goframe.org/os/gcron/index"
                                                                       target="_blank">https://goframe.org/os/gcron/index</a>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="protocol" value="HTTP" title="HTTP" checked>
                    <input type="radio" name="protocol" value="SHELL" title="SHELL">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">SHELL/URL</label>
                <div class="layui-input-block">
                    <textarea name="command" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">HTTP类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="method" value="POST" title="POST">
                    <input type="radio" name="method" value="GET" title="GET">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">单例</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_singleton" value="0" title="否" checked>
                    <input type="radio" name="is_singleton" value="1" title="是">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="0" title="禁用" checked>
                    <input type="radio" name="status" value="1" title="启用">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">超时时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="timeout" lay-verify="" value="0" autocomplete="off"
                           class="layui-input">
                </div>
                <tip>0不限制,单位(秒)</tip>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">重试次数</label>
                <div class="layui-input-inline">
                    <input type="text" name="retry_count" lay-verify="" value="0" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">重试间隔</label>
                <div class="layui-input-inline">
                    <input type="text" name="retry_interval" lay-verify="" value="0" autocomplete="off"
                           class="layui-input">
                </div>
                <tip>单位(秒)</tip>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" name="remark" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'layer', 'tableSelect'], function () {
        var form = layui.form,
            layer = layui.layer,
            tableSelect = layui.tableSelect,
            $ = layui.$;

        //监听提交
        form.on('submit(submit)', function (data) {
            let id = "${.info.Id}"
            let method = 'post'
            if (id > 0) {
                method = 'put'
                data.field.id = id
            }
            $.ajax({
                url: "/api/cron",
                type: method,
                data: data.field,
                success: function (res) {
                    layer.msg(res.msg);
                    if (res.code === 0) {
                        parent.location.reload(); //成功后再刷新
                    }
                },
                error: function (res) {
                    layer.msg(res.msg);
                    return false
                }
            })
            return false;
        });

        //表单初始赋值
        form.val('edit', {
            "name": "${.info.Name}"
            , "pattern": "${.info.Pattern}"
            , "protocol": "${.info.Protocol}"
            , "command": "${.info.Command}"
            , "method": "${.info.Method}"
            , "is_singleton": "${.info.IsSingleton}"
            , "status": "${.info.Status}"
            , "timeout": "${.info.Timeout}"
            , "retry_count": "${.info.RetryCount}"
            , "retry_interval": "${.info.RetryInterval}"
            , "remark": "${.info.Remark}"
        })
    });
</script>

</body>
</html>